package com.itheima.demo04methodref;

import java.util.function.Consumer;

public class Demo01MethodRefIntro {
    public static void main(String[] args) {
        //使用Lambda表达式求一个数组的和
        printMax(
                (s) -> {
                    int sum = 0;
                    for (int i : s) {
                        sum += i;
                    }
                    System.out.println("sum = " + sum);
                }
        );

        printMax(s->getMax(s));
        //使用方法引用
        printMax(Demo01MethodRefIntro::getMax);

    }

    public static void printMax(Consumer<int[]> consumer) {
        int[] arr = {11,22,33,44,55};
        consumer.accept(arr);
    }

    //获取数组最大值
    public static void getMax(int[] arr){
        int sum=0;
        for (int n : arr) {
            sum+=n;
        }
        System.out.println(sum);
    }
}
